package com.yezong.AidMe.service;

import com.yezong.AidMe.entity.CtUser;
import com.yezong.AidMe.entity.User;
import com.yezong.AidMe.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.logging.Logger;

@Service
public class UserService {

    Logger logger = Logger.getLogger("UserService");

    @Autowired
    private UserMapper userMapper;

    public User login(User user) {
        logger.info(user.toString());

        User user1 = userMapper.selectOneByPhonenumberAndPassword(user);
        logger.info("User:" + (user1 != null ? user1.toString() : "null"));

        return user1;
    }

    public boolean register(User user){
        logger.info(user.toString());

        int result = userMapper.insertUser(user);
        logger.info("User:" + (result > 0 ? "注册成功" : "注册失败"));

        return result > 0 ? true : false;
    }

    public boolean certify(CtUser ctUser) {
        logger.info(ctUser.toString());

        CtUser ctUser1 = userMapper.certifyStudentInfo(ctUser);
        logger.info("User:" + (ctUser1 != null ? ctUser1.toString() : "null"));

        return ctUser1 != null ? true : false;
    }

    public User selectOneById(Integer id) {

        return userMapper.selectOneById(id);

    }

    public boolean updateUser(User user) {return userMapper.updateUser(user) > 0;}

    public boolean deleteUser(int id) {return userMapper.deleteUser(id) > 0;}

    public boolean updateStudentCertifiedInfo(String number) {return userMapper.updateStudentCertifiedInfo(number) > 0;}

    public boolean updateUserCertifiedInfo(int id, String number) {return userMapper.updateUserCertifiedInfo(id, number) > 0;}

    public String[] selectInterest(Integer id) {return userMapper.selectInterest(id).split(",");}
}

